﻿using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(PolygonCollider2D))]
public class Shape2D : MonoBehaviour
{
    public Color LineColor;

    [HideInInspector]
    public List<Vector2> vertices = new List<Vector2>();

    [HideInInspector]
    public PolygonCollider2D colider;

    void Start()
    {
        LineColor = Color.green;
        colider = GetComponent<PolygonCollider2D>();
    }

    void UpdateShape()
    {
        vertices.Clear();
        Matrix4x4 matrix = transform.localToWorldMatrix;
        for (int i = 0; i < colider.points.Length; i++)
        {
            Vector2 point = colider.points[i];
            vertices.Add(matrix.MultiplyPoint(point));
        }
    }

    public void DrawPolygon()
    {
        UpdateShape();
        LineTool.Instance.DrawPolygon(vertices, LineColor);
    }
}